<?php

/* 优惠活动 activity */
class ActivityModel extends BaseModel
{
    var $table  = 'activity';
    var $prikey = 'act_id';
    var $_name  = 'activity';
    var $_relation  = array(
        'has_activitygoods' => array(
            'model'         => 'activitygoods',
            'type'          => HAS_MANY,
            'foreign_key'   => 'act_id',
            'dependent'     => true
        ),
        'has_goods' => array(
            'model'         => 'goods',
            'type'          => HAS_MANY,
            'foreign_key'   => 'act_id',
            'dependent'     => true
        ),

    );

    /**
     * 获取参与活动的商品数据
     *
     * @author    yanghj  2015.04.22
     * @param     $act_ids array 或者 int   活动的ID数组或者活动ID
     *
     */
    function _get_activity_list($act_ids = 0)
    {

        $conditions = "start_time < ".gmtime()." AND end_time > ".gmtime()." AND act_id " . db_create_in($act_ids);
        $activity = $this->find(array(
            'conditions'    => $conditions,
            'fields'    => 'act_id, act_name, start_time, end_time,discount_type, free_shipping',
        ));
        return $activity;
    }
    
}

?>
